package com.ben.chatroom.common.result;

import lombok.Data;

import java.io.Serializable;

/**
 * @author huangyijun
 */
@Data
public class Result<T> implements Serializable {

  public int code;

  private String msg;

  private T data;

  public Result() {
    this.code = 200;
    this.msg = "操作成功";
  }

  public Result(T data) {
    this.code = 200;
    this.msg = "操作成功";
    this.data = data;
  }

  public static Result error() {
    return error(500, "未知异常，请联系管理员");
  }

  public static Result error(String msg) {
    return error(500, msg);
  }

  public static Result error(int code, String msg) {
    Result r = new Result();
    r.setCode(code);
    r.setMsg(msg);
    return r;
  }

  public static Result ok(String msg) {
    Result r = new Result();
    r.setMsg(msg);
    return r;
  }


  public static Result ok() {
    return new Result();
  }
}
